﻿using durable.xml.ConfigProvider;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Durable.DControl
{
    public class DataGridControl
    {
        XmlProvider xml = new XmlProvider();
        string CustomCheckInfopath = string.Empty;
        public DataGridControl()
        {
            CustomCheckInfopath = Application.StartupPath + "/Config/CustomCheckInfo.xml";
        }
        public void CustomCheckInfoData(string value, System.Windows.Forms.DataGridView DataGridView)
        {
          
            xml._XmlAPIPath = CustomCheckInfopath;
            List<dynamic> list=  xml.Fill("Caliber", value);
            DataGridView.AutoGenerateColumns = false;
           
            DataGridView.Columns.Clear();
            DataGridView.Columns.Add(AddColumn("code", "",0,true,false));
            DataGridView.Columns.Add(AddColumn("id", "序号",90,true));
            DataGridView.Columns.Add(AddColumn("Caliber", "口径",90,true));
            DataGridView.Columns.Add(AddColumn("flow", "瞬时流量",240));
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn("code"));
            dt.Columns.Add(new DataColumn("id"));
            dt.Columns.Add(new DataColumn("Caliber"));
            dt.Columns.Add(new DataColumn("flow"));

            foreach (var item in list)
            {
                DataRow dr = dt.NewRow();
                dr[0] = item["code"];
                dr[1] = item["id"];
                dr[2] = item["Caliber"];
                dr[3] = item["flow"];
                dt.Rows.Add(dr);
            }

            DataGridView.DataSource = dt;
           

        }
        private DataGridViewTextBoxColumn AddColumn(string PropertyName, string Text,int heigth,bool read = false,bool flag= true)
        {
            DataGridViewTextBoxColumn textBoxColumn = new DataGridViewTextBoxColumn();
            textBoxColumn.DataPropertyName = PropertyName;
            textBoxColumn.Name = PropertyName;
            textBoxColumn.HeaderText = Text;
            textBoxColumn.Visible = flag;
            textBoxColumn.Width = heigth;
            textBoxColumn.ReadOnly = read;
            textBoxColumn.Resizable = DataGridViewTriState.False;
            return textBoxColumn;
        }

    }
}
